#!/usr/bin/python2

import argparse 
import numpy as np

from get_features import *
from sql import *

parser = argparse.ArgumentParser()
parser.add_argument('img', type=str, help="Input image.")
args = parser.parse_args()

bgr_img = cv2.imread(args.img)
if bgr_img is None:
    raise Exception("Unable to load image: {}".format(args.img))
rgb_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2RGB)

face = get_face(rgb_img)

results = search(face)

facelist = []
for result in results:
    array = np.zeros(128)
    for x in range(128):
        array[x] = result[x]
    array -= face
    comp = np.dot(array,array)
    if comp < 1.0:
        facelist.append([comp,result[128]])
facelist.sort()

print("<ul>")

for face in facelist:
    print("<li><img src=/thumbnails128x128/{}><p>{}</p></li>".format(face[1],face[0]))

print("</ul>")
